<?php

if (!defined('BASEPATH'))
  exit('No direct script access allowed');


class Visitor extends CI_Model {

	var $_table_name = 'visitor';

	public function __construct() {
    	$this->load->database();
  	}

  	public function is_exist($ip){

  		$this->db->select('*');
  		$this->db->from($this->_table_name);
  		$this->db->where('ip', $ip);

  		$query = $this->db->get();
  		return $query->num_rows();
  	}

  	public function plus($ip){
  		$this->db->set('visit_count','visit_count+1', TRUE);

  		$this->db->where('ip', $ip);
  		$this->db->update($this->_table_name);

  		return $this->db->affected_rows();
  	}

  	public function insert($insertData){

        $this->db->insert($this->_table_name, $insertData);
        return $this->db->insert_id();
    }
}